<template>
  <div class="login-wrap clearfix">
    <!-- 欢迎模块 -->
    <div class="welcome-box left">
      <h1>Welcome</h1>
      <div class="line"></div>
      <h4>好新优运营管理系统</h4>
      <p>—— 社交新零售电商平台 ——</p>
    </div>

    <!-- 找回密码模块 -->
    <div class="login-box find-box left">
      <div class="logo">
        <img src="../assets/image/logo.png" alt="logo" />
      </div>

      <el-input
        placeholder="请输入手机号"
        prefix-icon="el-icon-mobile-phone"
        v-model="name">
      </el-input>

      <div class="captcha-box">
        <el-input
          class="password"
          placeholder="请输入验证码"
          prefix-icon="el-icon-mouse"
          v-model="captcha">
        </el-input>
        <el-button type="primary">获取验证码</el-button>
      </div>

      <el-input
        class="password"
        placeholder="请输入新密码"
        prefix-icon="el-icon-lock"
        v-model="newPassword">
      </el-input>

      <el-input
        class="password"
        placeholder="请确认新密码"
        prefix-icon="el-icon-unlock"
        v-model="confirmPassword">
      </el-input>

      <el-button
        type="primary"
        class="btn edit-btn"
        @click="hangleEditPassword()"
      >确认</el-button>
    </div>

    <!-- 备案信息 -->
    <div class="company-info">
      <p>版权所有 Copyright © 2018-2020 广州好新优科技有限公司</p>
      <p>粤ICP备 19122864号</p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tip: '',
      name: '',
      password: '',
      captcha: '',
      captchaImg: '',
      newPassword: '',
      confirmPassword: '',
      checked: false
    }
  },

  created () {
    // this.getCaptcha()
  },

  methods: {
    // 登录
    handleLogin() {
      const that = this
      let valid = this.validateMsg()

      // if(valid){
      //   that.axios({
      //     method: 'GET',
      //     url: process.env.API_ROOT + '/openApi/login/login?username=' + that.name +'&password=' + that.password + '&kaptcha=' + that.captcha
      //   }).then((res) =>{
      //     if (res.data.code == 200) {
      //       that.$message({
      //         type: 'success',
      //         message: '登录成功!'
      //       })

      //       that.getUserInfo()

      //       setTimeout(function() {
      //         that.$router.push({path: '/index'})
      //       }, 1000)
      //     } else {
      //       that.getCaptcha()
      //       that.$message.error(res.data.msg)
      //     }
      //   }).catch((error) =>{
      //     if (error.response) {
      //       if (error.response.status == 400) {
      //         that.getCaptcha()
      //         that.$message.error('验证码不正确')
      //       }
      //     } else if (error.request) {
      //       console.log(error.request);
      //     } else {
      //       console.log('Error', error.message);
      //     }
      //   })
      // }
    },

    // 找回密码
    handleFindPassword() {
      this.login = false
    },

    // 申请入驻
    handleApply() {

    },

    // 获取管理员信息
    getUserInfo () {
      this.axios({
        method: 'POST',
        url: process.env.API_ROOT + '/admin/admin/getLogin'
      }).then((res) =>{
        if (res.data.code == 200) {
          localStorage.setItem('hxyUserName', res.data.data.username)
        } else {
          this.$message.error('获取信息失败')
        }
      }).catch((error) =>{
        console.log(error)
      })
    },

    // 验证必要信息
    validateMsg () {
      let tipName = '请填写账号！'
      let tipPassword = '请输入密码！'
      // let tipCaptcha = '请输入验证码！'

      if (this.name == '') {
        this.$message.error(tipName)
        return false
      }

      if (this.password == '') {
        this.$message.error(tipPassword)
        return false
      }

      // if (this.captcha == '') {
      //   this.$message.error(tipCaptcha)
      //   return false
      // }

      return true
    },

    // 获取验证码，这里要处理返回的数据
    getCaptcha () {
      this.axios({
        method: 'GET',
        responseType: 'arraybuffer',
        url: process.env.API_ROOT + '/kaptcha'
      }).then(response => {
    　　return 'data:image/png;base64,' + btoa(
    　　　new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
    　　)
      }).then((data) =>{
        this.captchaImg = data
      }).catch((error) =>{
        this.$message.error('获取验证码失败，请重新尝试')
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  text-align: center;
  background: url('../assets/image/login_bg.png') no-repeat center;

  .welcome-box {
    padding-top: 40px;
    width: 380px;
    height: 430px;
    text-align: center;
    color: #fff;
    background: url('../assets/image/welcome_bg.png') no-repeat center;

    h1 {
      font-size: 50px;
    }

    .line {
      margin: 16px auto 8px;
      width: 36px;
      height: 5px;
      background-color: #fff;
      border-radius: 5px;
    }

    h4 {
      font-size: 30px;
    }

    p {
      margin-top: 12px;
      font-size: 14px;
    }
  }

  .login-box {
    width: 410px;
    height: 470px;
    background-color: #fff;
    border-radius: 4px;

    .logo {
      padding: 45px 0;
      text-align: center;

      img {
        width: 100px;
      }
    }

    .el-input {
      margin: 0 auto 20px;
      width: 244px;
      font-size: 14px;
      color: #999;
      border-bottom: 1px solid #ccc;
    }

    >>> .el-input__inner {
      font-size: 16px;
      border: none;
    }

    >>> .el-input__icon {
      width: 0;
      font-size: 16px;
    }

    .password {
      margin: 0 auto 15px;
    }

    .captcha-box {
      position: relative;
      margin: 0 auto;
      width: 244px;
      text-align: left;

      >>> .el-input__inner {
        width: 160px;
      }

      .el-button {
        position: absolute;
        right: 0;
        bottom: 24px;
        padding: 0;
        width: 90px;
        height: 28px;
        font-size: 12px;
        background-color: #3a88f7;
        border-color: #3a88f7;
        border-radius: 14px;
      }
    }

    .operation {
      margin: 0 auto 30px;
      width: 244px;

      .left {
        color: #3a88f7;
      }

      .right {
        color: #7f7f7f;
      }

      .left,
      .right {
        cursor: pointer;
      }
    }

    .operation,
    .el-checkbox {
      color: #999;
    }

    .btn {
      margin-bottom: 20px;
      width: 244px;
      height: 44px;
      text-align: center;
      font-size: 18px;
      border-radius: 4px;
    }

    .captcha-btn {
      width: 90px;
      height: 28px;
      line-height: 28px;
      text-align: center;
      font-size: 12px;
      color: #fff;
      background-color: #3a88f7;
      border-radius: 10px;
    }

    .login-btn,
    .edit-btn {
      color: #fff;
      background-color: #3a88f7;
    }

    .edit-btn {
      margin-top: 20px;
    }

    .apply-btn {
      color: #4c4c4c;
      background-color: #fff;
      border: 1px solid #999;
    }

    .el-button+.el-button {
      margin-left: 0;
    }
  }

  .company-info {
    position: absolute;
    bottom: 2%;
    line-height: 18px;
    text-align: center;
    font-size: 12px;
    color: #fff;
  }
}

.ie9 .login-box {
  margin: 5% auto 0;
}
</style>
